package com.codedancer.campus.manager.api.commentReport;

import cn.hutool.core.bean.BeanUtil;
import com.codedancer.campus.common.anno.InterfacePermission;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import com.codedancer.campus.manager.api.commentReport.ro.CommentReportTypeAddOrUpdateRo;
import com.codedancer.campus.manager.api.commentReport.ro.CommentReportTypeSearchRo;
import com.codedancer.campus.manager.service.ICommentReportTypeService;
import com.codedancer.campus.manager.service.bo.commentReport.CommentReportTypeAddOrUpdateBo;
import com.codedancer.campus.manager.service.bo.commentReport.CommentReportTypeSearchBo;
import com.codedancer.campus.manager.service.vo.commentReport.CommentReportTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/comment-report-type")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "评论举报类型Api", description = "评论举报类型Api", tags = "评论举报类型Api")
public class CommentReportTypeApi extends BaseApi {

  @Autowired
  private ICommentReportTypeService commentReportTypeService;

  @PostMapping("/add")
  @ApiOperation("添加评论举报类型")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<Void> add(
      @RequestBody @Valid @ApiParam(value = "添加评论举报类型Ro", readOnly = true)
      CommentReportTypeAddOrUpdateRo commentReportTypeAddOrUpdateRo) {
    CommentReportTypeAddOrUpdateBo commentReportTypeAddOrUpdateBo = BeanUtil.copyProperties(
        commentReportTypeAddOrUpdateRo, CommentReportTypeAddOrUpdateBo.class);
    commentReportTypeService.add(commentReportTypeAddOrUpdateBo);
    return success();
  }

  @PutMapping("/update/{uuid}")
  @ApiOperation("修改评论举报类型")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<Void> update(
      @RequestBody @Valid @ApiParam(value = "修改评论举报类型Ro", readOnly = true)
      CommentReportTypeAddOrUpdateRo commentReportTypeAddOrUpdateRo,
      @PathVariable(value = "uuid", required = true) @ApiParam(value = "评论举报类型uuid", readOnly = true) String uuid) {
    CommentReportTypeAddOrUpdateBo commentReportTypeAddOrUpdateBo = BeanUtil.copyProperties(
        commentReportTypeAddOrUpdateRo, CommentReportTypeAddOrUpdateBo.class);
    commentReportTypeAddOrUpdateBo.setUuid(uuid);
    commentReportTypeService.update(commentReportTypeAddOrUpdateBo);
    return success();
  }

  @GetMapping("/list")
  @ApiOperation("获取全部评论举报类型")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<List<CommentReportTypeVo>> list(
      @ApiParam(value = "评论举报类型搜索Ro", required = false)
      CommentReportTypeSearchRo commentReportTypeSearchRo) {
    return success(commentReportTypeService.list(BeanUtil.copyProperties(commentReportTypeSearchRo,
        CommentReportTypeSearchBo.class)));
  }

  @DeleteMapping("/delete/{uuid}")
  @ApiOperation("删除评论举报类型")
  @InterfacePermission(encodes = {"superAdmin"})
  public ApiResponse<Void> delete(
      @PathVariable(value = "uuid", required = true) @ApiParam(value = "评论举报类型uuid", readOnly = true) String uuid) {
    commentReportTypeService.delete(uuid);
    return success();
  }
}
